{extend name="common/main"}

{block name="css"}
<link href="https://cdn.staticfile.org/font-awesome/4.4.0/css/font-awesome.css?v=4.4.0" rel="stylesheet">
<link rel="stylesheet" href="/static/jsTree/style.min.css"/>
<style>
    .jstree-open > .jstree-anchor > .fa-folder:before {
        content: "\f07c"
    }

    .jstree-default .jstree-icon.none {
        width: 0
    }
    .lai{
        float: none;
        display:inline-block;
    }
</style>
{/block}

{block name="body"}
<body data-type="widgets">
{include file="common/index"}
<!-- 内容区域 -->
<div class="tpl-content-wrapper">
    <div class="row-content am-cf">
        <!--客户-->
        <div class="row">
            <div class="am-u-sm-4 am-u-md-4 am-u-lg-4">
                <!--<h3 class="widget-title  am-cf">全部客户</h3>-->
                <div class="widget am-cf">

                    <div class="widget-head am-cf">
                        <div class="widget-title  am-cf">目标客户</div>
                    </div>

                    <div class="col-sm-6">
                        <div class="ibox float-e-margins">
                            <div class="ibox-content">
                                <!--无限目录  用户 -->
                                <div id="jstree1">
                                    <ul>
                                        {$menu}
                                    </ul>
                                </div>
                                <!--/无限目录  用户 -->
                            </div>
                        </div>
                    </div>

                </div>
            </div>
        </div>

        <div class="row">

            <div class="am-u-sm-6 am-u-md-6 am-u-lg-6">
                <!--<h3>新增用户</h3>-->
                <div class="widget am-cf">

                    <div class="widget-head am-cf">
                        <div class="widget-title  am-cf">新增用户</div>
                    </div>

                    <div class="widget-body am-fr">

                        <form form="submit" id="form" class="am-form tpl-form-border-form tpl-form-border-br " >

                            <div class="am-form-group">
                                <label  class="am-u-sm-2">上级客户: </label>
                                <div class="am-u-sm-5 lai" >
                                    <input type="text" disabled="true" id="sname" name="sname" value="{$name}">
                                    <input type="hidden" id="follow_id" name="follow_id" value="{$follow_id}">
                                </div>
                            </div>

                            <div class="am-form-group">
                                <label  class="am-u-sm-2">名称: </label>
                                <div class="am-u-sm-5 lai" >
                                    <input type="text" id="nickname"  name="nickname">
                                </div>
                            </div>

                            <div class="am-form-group">
                                <label  class="am-u-sm-2">登陆账号:</label>
                                <div class="am-u-sm-5 lai" >
                                    <input type="text" id="phone" name="phone">
                                </div>
                            </div>

                            <div class="am-form-group">
                                <label  class="am-u-sm-2">密码: </label>
                                <div class="am-u-sm-5 lai" >
                                    <input type="password" id="password" name="password">
                                </div>
                            </div>

                            <div class="am-form-group">
                                <label  class="am-u-sm-2">确认密码: </label>
                                <div class="am-u-sm-5 lai" >
                                    <input type="password" id="user_passvr" name="user_passvr">
                                </div>
                            </div>
                            <button type="button" class="am-btn am-btn-primary am-radius clor" style=" padding: .3em 1em;" onclick="roleSubmit()">确定</button>
                            <a href="{:url('User/menu')}" data-toggle="tooltip" title="" class="am-btn am-btn-primary am-radius">返回</a>
                        </form>
                    </div>
                </div>
            </div>
        </div>


    </div>
</div>
</body>
{/block}
{block name="js"}
<script src="https://cdn.bootcss.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<script src="/static/jsTree/content.min.js"></script>
<script src="/static/jsTree/jsTree.min.js"></script>
<script>
        $(document).ready(function () {
            $("#jstree1").jstree({
                "core": {"check_callback": true},
                "plugins": ["types", "dnd"],
                "types": {
                    "default": {"icon": "fa fa-user-secret"},
                    "img": {"icon": "fa fa-user"}
                }
            });
            $('#jstree1 .jstree-anchor').on('click', function (e, data) {
                menu_id=$(this).parent().attr("menu_id"); //用户名称id
                sname =$(this).text(); //用户名称
                $('#sname').val(sname);
                $('#follow_id').val(menu_id)
            });

    });
        //提交
        function roleSubmit() {
            var form = document.getElementById("form");
            var formData = new FormData(form);
                $.ajax({
                    url: "{:Url('User/roleadd')}",
                    type: 'POST',
                    data: formData,
                    async: false,
                    cache: false,
                    contentType: false, //不设置内容类型
                    processData: false, //不处理数据
                    success: function (res) {
                        if (res.code != 200) {
                            layer.msg(res.msg, {shade: 0.5, time: 1000, icon: 2});
                            return false;
                        }
                        layer.msg(res.msg, {shade: 0.5, time: 800, icon: 1}, function () {
                            window.location.href=document.referrer;//返回上一个界面刷新
                        });
                    }
                });
        }
</script>
{/block}